Technical Q&As


The Apple Media Tool and Apple Media Tool Programming Environment products have been discontinued. For more information check out: AMT/PE Discontinued.

AMT_PE 21 - Getting the System Time (1-Aug-95)


Q Is there a way to get the system time? There doesn't appear to be a call for this in the Apple Media Tool.

A To get the system time from the host computer's operating system, you need to access the hardware's time facilities. You can add a new method to the CLOCK.k file, and create the appropriate interface in the CLOCK.c file. On the Macintosh, you can use GetTime(). Under Windows, use _strtime() and _strdate().

Even better, you can use the ANSII-standard LocalTime function, for both Windows and the Mac. Follow these steps:

1. Make a copy of the Clock.c and Clock.k files found in your ...:Key:Runtime:"Folder. Place the copies in your applications "sources" folder.

2. In YourProject.k comment out the line "Clock;" and add "Clock;" to the list of files under "include "SOURCES;";"

3. Modify your copy of Clock.k by adding the following method

GetTimeOfDay()
    external "ClockGetTimeOfDay";

4. Modify your copy of Clock.c by adding the following function:

     void ClockGetTimeOfDay (key* the)
     {   time_t now;
         struct tm *date;
         char *s
         now=time(NULL);
         date=localtime(&now);
         s=osctime(date);
         the[RESULT]=keyFromString(s);
     }


Technical Q&As
Previous Question | Contents | Next Question